package com.zxbit.flash.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zxbit.flash.R;
import com.zxbit.flash.bean.PayCodeDataNew;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订单的适配器
 */
public class PaycodeAdapter extends RecyclerView.Adapter<PaycodeAdapter.PayCodeHolder> {

    private OnCopyListener copyListener;
    private Context context;
    private List<PayCodeDataNew.PayCodeBean> data;

    public List<PayCodeDataNew.PayCodeBean> getData() {
        return data;
    }

    public void setData(List<PayCodeDataNew.PayCodeBean> data) {
        this.data = data;
    }

    public PaycodeAdapter(Context context, List<PayCodeDataNew.PayCodeBean> data) {
        this.context = context;
        this.data = data;

    }

    @NonNull
    @Override
    public PayCodeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_paycode, parent, false);

        return new PayCodeHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PayCodeHolder holder, int position) {

        final PayCodeDataNew.PayCodeBean payCodeBean = data.get(position);
        holder.tvPayType.setText(payCodeBean.getPayBankType());
        holder.tvCode.setText(payCodeBean.getPaymentCode());
        holder.tvCode.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (copyListener != null) {
                    copyListener.onCopyClick((TextView) v);
                }
                return true;
            }
        });

    }


    @Override
    public int getItemCount() {
        return data.size();
    }


    static class PayCodeHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tvPayType)
        TextView tvPayType;
        @BindView(R.id.tvCode)
        TextView tvCode;


        PayCodeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void setCopyListener(OnCopyListener listener) {
        this.copyListener = listener;
    }

    public interface OnCopyListener {
        void onCopyClick(TextView view);
    }
}
